//
//  SDDiagnoseSkinData.m
//
//  Created by   on 2018/11/26
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "SDDiagnoseSkinData.h"


NSString *const kSDDiagnoseSkinDataTypeId = @"typeId";
NSString *const kSDDiagnoseSkinDataImg = @"img";
NSString *const kSDDiagnoseSkinDataScore = @"score";
NSString *const kSDDiagnoseSkinDataId = @"id";
NSString *const kSDDiagnoseSkinDataAnalysis = @"analysis";
NSString *const kSDDiagnoseSkinDataSubName = @"subName";
NSString *const kSDDiagnoseSkinDataProposal = @"proposal";
NSString *const kSDDiagnoseSkinDataDiagnosis = @"diagnosis";
NSString *const kSDDiagnoseSkinDataDesc = @"desc";


@interface SDDiagnoseSkinData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation SDDiagnoseSkinData

@synthesize typeId = _typeId;
@synthesize img = _img;
@synthesize score = _score;
@synthesize id = _id;
@synthesize analysis = _analysis;
@synthesize subName = _subName;
@synthesize proposal = _proposal;
@synthesize diagnosis = _diagnosis;
@synthesize desc = _desc;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.typeId = [[self objectOrNilForKey:kSDDiagnoseSkinDataTypeId fromDictionary:dict] doubleValue];
            self.img = [self objectOrNilForKey:kSDDiagnoseSkinDataImg fromDictionary:dict];
            self.score = [[self objectOrNilForKey:kSDDiagnoseSkinDataScore fromDictionary:dict] doubleValue];
            self.id = [[self objectOrNilForKey:kSDDiagnoseSkinDataId fromDictionary:dict] doubleValue];
            self.analysis = [self objectOrNilForKey:kSDDiagnoseSkinDataAnalysis fromDictionary:dict];
            self.subName = [self objectOrNilForKey:kSDDiagnoseSkinDataSubName fromDictionary:dict];
            self.proposal = [self objectOrNilForKey:kSDDiagnoseSkinDataProposal fromDictionary:dict];
            self.diagnosis = [self objectOrNilForKey:kSDDiagnoseSkinDataDiagnosis fromDictionary:dict];
            self.desc = [self objectOrNilForKey:kSDDiagnoseSkinDataDesc fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.typeId] forKey:kSDDiagnoseSkinDataTypeId];
    [mutableDict setValue:self.img forKey:kSDDiagnoseSkinDataImg];
    [mutableDict setValue:[NSNumber numberWithDouble:self.score] forKey:kSDDiagnoseSkinDataScore];
    [mutableDict setValue:[NSNumber numberWithDouble:self.id] forKey:kSDDiagnoseSkinDataId];
    [mutableDict setValue:self.analysis forKey:kSDDiagnoseSkinDataAnalysis];
    [mutableDict setValue:self.subName forKey:kSDDiagnoseSkinDataSubName];
    [mutableDict setValue:self.proposal forKey:kSDDiagnoseSkinDataProposal];
    [mutableDict setValue:self.diagnosis forKey:kSDDiagnoseSkinDataDiagnosis];
    [mutableDict setValue:self.desc forKey:kSDDiagnoseSkinDataDesc];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.typeId = [aDecoder decodeDoubleForKey:kSDDiagnoseSkinDataTypeId];
    self.img = [aDecoder decodeObjectForKey:kSDDiagnoseSkinDataImg];
    self.score = [aDecoder decodeDoubleForKey:kSDDiagnoseSkinDataScore];
    self.id = [aDecoder decodeDoubleForKey:kSDDiagnoseSkinDataId];
    self.analysis = [aDecoder decodeObjectForKey:kSDDiagnoseSkinDataAnalysis];
    self.subName = [aDecoder decodeObjectForKey:kSDDiagnoseSkinDataSubName];
    self.proposal = [aDecoder decodeObjectForKey:kSDDiagnoseSkinDataProposal];
    self.diagnosis = [aDecoder decodeObjectForKey:kSDDiagnoseSkinDataDiagnosis];
    self.desc = [aDecoder decodeObjectForKey:kSDDiagnoseSkinDataDesc];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_typeId forKey:kSDDiagnoseSkinDataTypeId];
    [aCoder encodeObject:_img forKey:kSDDiagnoseSkinDataImg];
    [aCoder encodeDouble:_score forKey:kSDDiagnoseSkinDataScore];
    [aCoder encodeDouble:_id forKey:kSDDiagnoseSkinDataId];
    [aCoder encodeObject:_analysis forKey:kSDDiagnoseSkinDataAnalysis];
    [aCoder encodeObject:_subName forKey:kSDDiagnoseSkinDataSubName];
    [aCoder encodeObject:_proposal forKey:kSDDiagnoseSkinDataProposal];
    [aCoder encodeObject:_diagnosis forKey:kSDDiagnoseSkinDataDiagnosis];
    [aCoder encodeObject:_desc forKey:kSDDiagnoseSkinDataDesc];
}

- (id)copyWithZone:(NSZone *)zone {
    SDDiagnoseSkinData *copy = [[SDDiagnoseSkinData alloc] init];
    
    
    
    if (copy) {

        copy.typeId = self.typeId;
        copy.img = [self.img copyWithZone:zone];
        copy.score = self.score;
        copy.id = self.id;
        copy.analysis = [self.analysis copyWithZone:zone];
        copy.subName = [self.subName copyWithZone:zone];
        copy.proposal = [self.proposal copyWithZone:zone];
        copy.diagnosis = [self.diagnosis copyWithZone:zone];
        copy.desc = [self.desc copyWithZone:zone];
    }
    
    return copy;
}


@end
